﻿using Prism.Navigation.Regions;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PrismRegion.Base.Views;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    private readonly IRegionManager _regionManager;

    public MainWindow(IRegionManager regionManager)
    {
        InitializeComponent();

        _regionManager = regionManager;

        _regionManager.RegisterViewWithRegion("ViewRegion", "ViewA");
        _regionManager.RegisterViewWithRegion("ViewRegion", "ViewB");

        this.Loaded += MainWindow_Loaded;
    }

    private void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        _regionManager.AddToRegion("ViewRegion", "ViewA");

        var region = _regionManager.Regions["ViewRegion"];
        var view = region.Views.FirstOrDefault(v => v.GetType().Name == "ViewB");
        region.Activate(view);

        region.Add(new ViewB());
    }
}